<%-- 
    Document   : emailTemplate1
    Created on : Mar 5, 2013, 8:15:42 PM
    Author     : mudassar
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@include file="../common/script.jsp" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="../common/title.jsp" %>
        <script type="text/javascript">
            $(function() {  
                $( "#appointmentDate" ).datetimepicker({dateFormat: 'dd-mm-yy',stepMinute:15, hourMin:8,hourMax:21,minDate:0});
            });
        </script>

        <script type="text/javascript">
            var rules=new Array();
            rules[0]='centerId|required|please Select centre';
            rules[1]='doctorId|required|please Select Doctor';
            rules[2]='appointmentDate|required|please Select appointment date';
            rules[3]='serviceId|required|please Select service';
            rules[4]='hospitalId|required|please Select hospital';
        </script>
        <script type="text/javascript">
            var hospitalName;
            var hospitalName1;
            function createEmailBody(){
                var centerId;
                var centerName;
                var doctorId;
                var doctorName;
                var appointmentDate;
                var serviceName;
                var centerContact;
                
                var emailTypeId = '${emailTypeId}';
                var customerId = '${customer.customerId}';
                var customerName = '${customer.customerName}';
                var mrNo = '${customer.mrNo}';
                var phone1 = '${customer.phone1}';
                var address = '${customer.address}';
                var cheifComplaint = '${customer.cheifComplaint}';
               
                if(emailTypeId==1 || emailTypeId==2 || emailTypeId==5  ){
                    centerId = document.getElementById("centerId").value;
                    id = document.getElementById("centerId");
                    var centreInfo = id.options[id.selectedIndex].text;
                    centerName=centreInfo.replace(/[^A-Za-z]+/g, " ");
                    centerContact=centreInfo.replace(/[^0-9+]+/g, " ");
                    //centerName = document.getElementById("centerId")[document.getElementById("centerId").selectedIndex].innerHTML;
                }
                if(emailTypeId==1 || emailTypeId==2 || emailTypeId==4 || emailTypeId==7 ){
                    doctorId = document.getElementById("doctorId").value;
                    doctorName = document.getElementById("doctorId")[document.getElementById("doctorId").selectedIndex].innerHTML;
                }
                // var doctorName = doctorId.options[doctorId.selectedIndex].text;
                //doctorName = 'doctorName';
                if(emailTypeId==1 || emailTypeId==2 ){
                    appointmentDate = document.getElementById("appointmentDate").value;
                }
                if(emailTypeId==6 ){
                    serviceName = document.getElementById("serviceId")[document.getElementById("serviceId").selectedIndex].innerHTML;
                }
                if(emailTypeId==8 ){
                    $(function() {
                        $( "#hospitalId" ).autocomplete({
                            source: "../ajaxCallForHospitalListForEmail.htm",
                            minLength: 1 ,
                            select: function(event, ui) {
                                hospitalName=ui.item.label;
                                createEmailBody();
                            }
                        });
                    });
                    hospitalName1= hospitalName.toString();
                }
                //alert('hospitalName outside:'+hospitalName);
                
                //alert('hospitalName1: '+hospitalName1);
                var data = {'customerName':customerName,'customerId':customerId,'emailTypeId':emailTypeId, 'centerId' : centerId,'centerName' :centerName,'centerContact':centerContact ,'doctorId' :doctorId, 'doctorName' :doctorName , 'appointmentDate':appointmentDate,'mrNo':mrNo,'phone1':phone1,'address':address, 'cheifComplaint':cheifComplaint,'serviceName':serviceName,'hospitalName':hospitalName1};
                
                $.ajax({
                    data: (data),
                    url: "../getEmailBody.htm",
                    dataType: "json",
                    success:function(json){
                        if(json!=null){
                            //alert("json area: "+json);
                            document.getElementById("emailBody").value=json;
                            document.getElementById("emailBodyForPreview").innerHTML=json;
                        }else{
                            //document.getElementById("area").value='';
                            
                        }
                    },
                    error: function(e){
                        
                        alert("Error:  Please Enter Info ");
                    }
                });
                
            }
        </script>
    </head>
    <body onload="createEmailBody();yav.init('form1',rules,'inline');">
        <%@include file="../common/header.jsp" %>
        <%@include file="../common/menu.jsp" %>
        <div class="in_02" >
            <form:form id="form1" name="form1" action="selectEmailTemplate.htm" method="POST" >
                <fieldset style="width: 1000px;">
                    <c:choose>
                        <c:when test="${emailTypeId==1}">
                            <legend><b>Appointment Email :</b></legend>
                        </c:when>
                        <c:when test="${emailTypeId==2}">
                            <legend><b>Appointment Intimation to centre :</b></legend>
                        </c:when>
                        <c:when test="${emailTypeId==3}">
                            <legend><b>Tele-consult feedback email :</b></legend>
                        </c:when>
                        <c:when test="${emailTypeId==4}">
                            <legend><b>Email to Doctor(After Tele-consult) :</b></legend>
                        </c:when>
                        <c:when test="${emailTypeId==5}">
                            <legend><b>Query about centre email :</b></legend>
                        </c:when>
                        <c:when test="${emailTypeId==6}">
                            <legend><b>Query about services email :</b></legend>
                        </c:when>
                        <c:when test="${emailTypeId==7}">
                            <legend><b>Doctor's followup reminder :</b></legend>
                        </c:when>
                        <c:otherwise>
                            <legend><b>ICICI Emergency intimation to HS Team :</b></legend>
                        </c:otherwise>
                    </c:choose>
                    <input type="hidden" id="emailTypeId" name="emailTypeId" value="${emailTypeId}"/>
                    <table>
                        <tr><c:if test="${emailTypeId==1 || emailTypeId==2 || emailTypeId==5 }">
                                <td style="padding:5px 30px 1px 5px;"  >  <spring:message code="centerName"/>:<br/>
                                    <select  id="centerId" name="centerId"  class="userInputLarge" onchange="createEmailBody();">
                                        <option value="" label="-">-</option>
                                        <c:forEach items="${centerList}" var="list">
                                            <option value="${list.centerId}">${list.centerName} ~ ${list.phoneNumber}</option>
                                        </c:forEach>
                                    </select><br/>
                                    <span id="errorsDiv_centerId"></span>
                                </td>
                            </c:if>
                            <c:if test="${emailTypeId==1 || emailTypeId==2 ||emailTypeId==7 || emailTypeId==4}">
                                <td style="padding:5px 30px 1px 5px;"><spring:message code="doctorName"/>:<br/>
                                    <select  id="doctorId" name="doctorId"  class="userInputLarge" onchange="createEmailBody();" >
                                        <option value="" label="-">-</option>
                                        <c:forEach items="${doctorList}" var="list">
                                            <option value="${list.doctorId}">${list.doctorName} </option>
                                        </c:forEach>
                                    </select><br/>
                                    <span id="errorsDiv_doctorId"></span> 
                                </td>
                            </c:if>
                            <c:if test="${emailTypeId == 6}">
                                <td style="padding:5px 30px 1px 5px;"><spring:message code="services"/>:<br/>
                                    <select  id="serviceId" name="serviceId"  class="userInputLarge" onchange="createEmailBody();" >
                                        <option value="" label="-">-</option>
                                        <c:forEach items="${serviceDetailsList}" var="list">
                                            <option value="${list.serviceId}">${list.serviceDesc} </option>
                                        </c:forEach>
                                    </select><br/>
                                    <span id="errorsDiv_serviceId"></span> 
                                </td>
                            </c:if>
                            <c:if test="${emailTypeId ==1 || emailTypeId==2}">
                                <td>Appointment Date:<br/>
                                    <input id="appointmentDate" name="appointmentDate" class="userInputLarge" onchange="createEmailBody();"/><br/>
                                    <span id="errorsDiv_appointmentDate"></span>
                                </td>
                            </c:if>
                            <c:if test="${emailTypeId ==8}">
                                <td>
                                    <p><label>Hospital Name:</label><br />
                                        <input type="text" name="hospitalId" id="hospitalId"  class="userInputLarge"  /><br/>
                                        <span id="errorsDiv_hospitalId"></span> 
                                </td>
                            </c:if>
                        </tr>
                   </table>
                    <table style="padding-top: 100px;padding-bottom: 100px;padding-left: 50px;padding-right: 50px;">
                        
                        <tr >
                            <td colspan="3" >
                                <input type="hidden" id="emailBody" name="emailBody"  readonly="true"/>
                                <div id="emailBodyForPreview" style="width: 100%;">

                                </div>
                            </td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td><input type="submit" name="_finish" value="<spring:message code="button.sendEmail"/>" onclick="return yav.performCheck('form1', rules, 'inline');"/></td>
                            <td><input type="submit" name="_cancel" value="<spring:message code="button.Cancel"/>" /></td>
                        </tr>
                        <input type="hidden" id="customerId" name="customerId" value="${customerId}"/>
                    </table>
                </fieldset>
            </form:form>
        </div>

    </body>
</html>
